import service from '@/utils/request';
import { saveAs } from 'file-saver';
export function blobValidate(data: any) {
  return data.type !== 'application/json'
}
// /itf/general/web/airport/{id}


/**
 * 获取机场数据by id
 * @param params  { keywords: null }
 * @returns 
 */
export function GetAirPortById(id: any) {
  return service({
    url: `/itf/general/web/airport/${id}`,
    method: 'get',
  })
}

/**
 * 获取机场数据
 * @param params  { keywords: null }
 * @returns 
 */
export function GetAirPort(params: any) {
  return service({
    url: '/itf/general/web/airport',
    method: 'get',
    params
  })
}


/**
 * 公共下载方法
 * @param params 参数
 * @param urls 地址
 * @param options 配置 { method: 'get', type: '.xls',fileName:'' }
 */
export async function PublicDownload(params: any, urls: string, options: any) {
  options = options ?? { method: 'get', type: '.xls', fileName: '' || new Date().getTime() }
  const data: any = await service({
    url: urls,
    method: options.method,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    responseType: 'blob',
    params
  });
  const { fileName, type } = options
  const blob = new Blob([data])
  saveAs(blob, fileName + type)
}

// 导入数据
export async function PublicExport(data: any, urls: string) {
  return service({
    url: urls,
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data
  });
}


/**
 * 全量查询多语言
 * @returns 
 */
export function GetLanguageList(params: any, open: boolean) {
  if (open) {
    return service({
      url: '/itf/general/open/multiple/language',
      method: 'get',
      params
    })
  }
  if (!open) {
    return service({
      url: '/itf/general/web/multiple/language',
      method: 'get',
      params
    })
  }

}

/**
 * 多语言配置分页查询
 * @param params 参数
 * @returns 
 */
export function GetLanguageListByPage(params: any) {
  return service({
    url: '/itf/general/web/multiple/language/page',
    method: 'get',
    params
  })
}


/**
 * 新增多语言配置
 * @param data body数据 
 * @returns 
 */
export function AddLanguage(data: any) {
  return service({
    url: '/itf/general/web/multiple/language',
    method: 'post',
    data
  })
}

/**
 * 编辑多语言配置
 * @param data body数据
 * @returns 
 */
export function EditLanguage(uuid: any, data: any) {
  return service({
    url: `/itf/general/web/multiple/language/uuid/${uuid}`,
    method: 'put',
    data
  })
}

/**
 * 删除多语言配置by uuid
 * @param uuid uuid
 * @returns 
 */
export function DeleteLanguageByUuid(uuid: any) {
  return service({
    url: `/itf/general/web/multiple/language/uuid/${uuid}`,
    method: 'delete'
  })
}

// 上传文件
export function Postupload(data: any) {
  return service({
    url: '/itf/general/web/oss/upload',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data
  })
}

// 字典
export function GetCodeDict(params: {}) {
  return service({
    url: '/itf/general/web/dict/data',
    method: 'get',
    params
  })
}

// 查询批量字典数据列表
export function GetBatchCodeDict(params: {}) {
  return service({
    url: '/itf/general/web/dict/data/batch',
    method: 'get',
    params
  })
}

// 删除字典数据
export function DeleteDictItem(uuid: any) {
  return service({
    url: `/itf/general/web/dict/data/uuid/${uuid}`,
    method: "delete",
  });
}

// 下载
export function GetDownload(params: {}) {
  return service({
    url: '/itf/general/web/oss/download',
    method: 'get',
    params
  })
}

/**
 * 查询国家列表(全量查询)
 * @param 
 * @returns 
 */
export function GetCountryLists() {
  return service({
    url: `/itf/general/web/country`,
    method: "get",
  });
}


/**
 * 获取是否为开发运维环境
 * @returns 
 */
export function IsGeneralApi() {
  return service({
    url: `/itf/general/open/devops`,
    method: 'get'
  })
}